home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1074 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  4.8 KB

  1. From: gregor@netcom.com (Greg Colvin)
  2. Message-ID: <gregorDps66M.1n7@netcom.com>
  3. X-Original-Date: Sat, 13 Apr 1996 03:11:09 GMT
  4. Path: in2.uu.net!bounce-back
  5. Date: 14 Apr 96 12:23:45 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: sample auto_ptr template
  9. Organization: Netcom Online Communications Services (408-241-9760 login: guest)
  10. References: <4kcr2d$p03@jabba.lehman.com> <KANZE.96Apr10111407@gabi.gabi-soft.fr> <AD9409799668E161@sleipner.nts.mh.se>
  11. Apparently-To: comp-std-c++@uunet.uu.net
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMXDueeEDnX0m9pzZAQGWMQF/dBWz3kikoM5Qsr4toRsElWKcROAh26Cb
  14.     JqfTnR5Kq86I+MuHDgGY/4rHujivMSXi
  15.     =/1E4
  16.  
  17. In article <AD9409799668E161@sleipner.nts.mh.se> lars.farm@nts.mh.se
  18. (Lars Farm) writes:
  19. >In article <KANZE.96Apr10111407@gabi.gabi-soft.fr>,
  20. >kanze@gabi-soft.fr (J. Kanze) wrote:
  21. >
  22. >>I believe that John Skaller had a proposal with something like six
  23. >>different pointer types.  The committee found this a little too
  24. >
  25. >He said a while ago that he proposed two classes(*). (1) auto_ptr for
  26. >lifetime control within a block (no copy/assign) and (2) a ref counted
  27. >class for shared objects. There is a need for both but only one was
  28. >accepted and that is the real problem.
  29. >
  30. >
  31. >auto_ptr<> is slowly being mutated into a mixture of the two classes. It
  32. >has moved away from its original goal and is becoming a cheap shared_ptr<>.
  33. >This requires very strange and disturbing use of op=/copy.
  34.  
  35. Yes, auto_ptr has evolved.  I don't find that strange or disturbing.
  36.  
  37. >
  38. >void f( auto_ptr<X> x ) { ...will delete x }
  39. >
  40. >  // promise: x const, x will _not_ change, x will _not_ become invalid
  41.  
  42. It is indeed a shame that all this promise cannot be kept for auto_ptr.  
  43. If someone can work out a change to the base language to allow for non-const
  44. copy operations, make sure that it doesn't break anything else, work out
  45. exact wording for the working paper, and convince the committee to accept
  46. the change, then I would gladly propose going back to an auto_ptr with
  47. non-const copy operations. 
  48.  
  49. Note that the promise of not becoming invalid cannot be kept for f(const X*)
  50. either.
  51.  
  52. >void g( const auto_ptr<X>&x ) {
  53. >  // ... x ok
  54. >  f(x);
  55. >  // ... oops
  56. >}
  57. >void h() {
  58. >   auto_ptr<X> p( new X );
  59. >   // p valid
  60. >   g(x);
  61. >   // p bad. Undetected by the compiler because the standard 
  62. >   // library class auto_ptr subverted the C++ type system
  63. >}
  64. >
  65. >IMHO the only reasonable solution is to have two classes. If the committee
  66. >only accepts one then users will have to write the other. That's ok, as
  67. >long as it is obvious that auto_ptr isn't a general purpose smart_ptr. With
  68.  
  69. IMHO the only general purpose smart pointer is a garbage collected smart
  70. pointer, which auto_ptr obviously is not.
  71.  
  72. >the current weird auto_ptr copy/op= perhaps users will have to write both
  73. >the original and the ref counted class on their own. Or worse, they will
  74. >actually use auto_ptr as if it was the rejected ref_counted ptr. This is a
  75. >reasonable assumption because auto_ptr is the only standard smart ptr and
  76. >users should be allowed to assume it is safe. It would be safe with private
  77. >op=/copy as the original.
  78.  
  79. The original auto_ptr was so limited that important uses would require
  80. the use of raw pointers and boolean flags, which are much less safe
  81. techniques than the current auto_ptr.  So you would need a counted_ptr
  82. for those uses, but the overhead of counted_ptr is just too high. We
  83. gave auto_ptr just enough copy semantics to support passing them to
  84. functions and returning them from functions. As a result, it becomes
  85. possible to use auto_ptr for some less safe idioms as well.  Given the
  86. infinity of unsafe idioms that C++ allows I just don't see the
  87. problem.
  88.  
  89. >
  90. >When designing a class for mass consumption it should not only support the
  91. >intended idioms. It should also prevent missuse in common situations. The
  92. >original does that. The current auto_ptr doesn't.
  93. >
  94.  
  95. >Please reconsider John Max Skallers original proposal.
  96. >
  97. >(*) he has also mentioned other smart pointers here. holding arrays -
  98. >block/ref-counted. copying pointers and cloning pointers using varying
  99. >implementation techniques but AFAIK they were never proposed as standard
  100. >classes.
  101. >
  102.  
  103. I don't recall Max making such a proposal, though he made many
  104. contributions to our discussion of smart pointers.  I can assure you
  105. that I would not insult the committee by asking them to reconsider a
  106. proposal that they have rejected more than once already.
  107.  
  108. Greg Colvin
  109. gregor@netcom.com
  110. ---
  111. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  112. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  113. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  114. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  115. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  116.